/**********************************************************************************************************
** 驱动文件：	jmkt-TUAR0721.c
** 驱动类型：	jmkt
** 设备名称：	精密空调
** 设备型号：	TUAR0721
** 设备品牌：	施耐德
** 设备协议：	UG40
** 驱动描述：	适用于施耐德控制器为UG40型精密空调。
** 生成日期：	2019-10-16 21:31:51
**********************************************************************************************************/
#include "Includes.h"


/**********************************************************************************************************
* 定义设备数据点变量结构
**********************************************************************************************************/
typedef struct{
	Var Fan;									//风机
	Var Compressor;								//压缩机
	Var Heater;									//加热器
	Var Dehumidification;						//除湿器
	Var Humidification;							//加湿器
	Var RoomTemperatureAlarm;					//室内温度报警
	Var RoomHumidityAlarm;						//室内湿度报警
	Var CloggedFilterAlarm;						//过滤器堵塞报警
	Var FloodingAlarm;							//漏水报警
	Var LossOfAirFlowAlarm;						//风压过低报警
	Var HeaterOverheatingAlarm;					//加热过热报警
	Var Circuit1PressureAlarm;					//回路1高/低压报警
	Var Circuit2PressureAlarm;					//回路2高/低压报警
	Var Circuit1ElectronicValveFailure;			//回路1电子阀故障
	Var Circuit2ElectronicValveFailure;			//回路2电子阀故障
	Var WrongPhaseSequenceAlarm;				//相序错误报警
	Var SmokeFireAlarm;							//烟/火报警
	Var LossOfWaterFlowAlarm;					//缺水报警
	Var HumidifierHighCurrentAlarm;				//加湿器过流报警
	Var HumidifierPowerLossAlarm;				//加湿器断电报警
	Var HumidifierWaterLossAlarm;				//加湿器缺水报警
	Var HumidifierGeneralAlarm;					//加湿器一般报警
	Var CWTemperatureHigh;						//冷冻水高温报警
	Var CWValveFailureWaterFlowLow;				//冷冻水阀故障或水流低报警
	Var RoomTempSensorFailed;					//室内温度传感器故障
	Var RoomHumiSensorFailed;					//室内湿度传感器故障
	Var OutdoorTempSensorFailed;				//室外温度传感器故障
	Var DeliveryAirTempSensorFailed;			//送风温度传感器故障
	Var RoomTemperature;						//室内温度
	Var OutdoorTemperature;						//室外温度
	Var DeliveryAirTemperature;					//送风温度
	Var InChilledWaterTemperature;				//冷水进水温度
	Var OutChilledWaterTemperature;				//冷水出水温度
	Var HotWaterTemperature;					//热水温度
	Var RoomRelativeHumidity;					//室内湿度
	Var CoolingSetpoint;						//制冷设定值
	Var CoolingSensitivity;						//制冷精度
	Var HeatingSetpoint;						//制热设定值
	Var HeatingSensitivity;						//制热精度
	Var DehumidificationSetpoint;				//除湿设定值
	Var DehumidificationSensitivity;			//除湿精度
	Var HumidificationSetpoint;					//加湿设定值
	Var HumidificationSensitivity;				//加湿精度
	Var Circuit1EvaporatingPressure;			//回路1蒸发器压力
	Var Circuit2EvaporatingPressure;			//回路2蒸发器压力
	Var Circuit1SuctionTemperature;				//回路1吸气温度
	Var Circuit2SuctionTemperature;				//回路2吸气温度
	Var Circuit1EvaporatingTemperature;			//回路1蒸发器温度
	Var Circuit2EvaporatingTemperature;			//回路2蒸发器温度
	Var Circuit1Superheat;						//回路1过热度
	Var Circuit2Superheat;						//回路2过热度
	Var ColdWaterValveRamp;						//冷水阀开度
	Var HotWaterValveRamp;						//热水阀开度
	Var EvaporatingFanSpeed;					//蒸发器风扇风速
	Var OnOffStatus;							//开关机状态
	Var AlarmStatus;							//报警状态
}Data_Struct;									//定义变量结构


/**********************************************************************************************************
* 设备数据点变量属性声明
**********************************************************************************************************/
const static Var_Property_Def var_attr[] = {
	{
		OCTSTR,
		0,
		READONLY,
		"Fan",
		"风机",
		"",
		"风机：0-运行，1-停止",
		0,
		0,
		"停止",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"Compressor",
		"压缩机",
		"",
		"压缩机：0-运行，1-停止",
		0,
		0,
		"停止",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"Heater",
		"加热器",
		"",
		"加热器：0-运行，1-停止",
		0,
		0,
		"停止",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"Dehumidification",
		"除湿器",
		"",
		"除湿：0-运行，1-停止",
		0,
		0,
		"停止",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"Humidification",
		"加湿器",
		"",
		"加湿：0-运行，1-停止",
		0,
		0,
		"停止",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"RoomTemperatureAlarm",
		"室内温度报警",
		"",
		"室内温度报警：0-正常，1-高温报警，2-低温报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"RoomHumidityAlarm",
		"室内湿度报警",
		"",
		"室内湿度报警：0-正常，1-高湿报警，2-低湿报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"CloggedFilterAlarm",
		"过滤器堵塞报警",
		"",
		"过滤器堵塞报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"FloodingAlarm",
		"漏水报警",
		"",
		"漏水报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"LossOfAirFlowAlarm",
		"风压过低报警",
		"",
		"风压过低报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"HeaterOverheatingAlarm",
		"加热过热报警",
		"",
		"加热过热报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"Circuit1PressureAlarm",
		"回路1高/低压报警",
		"",
		"回路1高/低压报警：0-正常，1-高压报警，2-低压报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"Circuit2PressureAlarm",
		"回路2高/低压报警",
		"",
		"回路2高/低压报警：0-正常，1-高压报警，2-低压报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"Circuit1ElectronicValveFailure",
		"回路1电子阀故障",
		"",
		"回路1电子阀故障：0-正常，1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"Circuit2ElectronicValveFailure",
		"回路2电子阀故障",
		"",
		"回路2电子阀故障：0-正常，1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"WrongPhaseSequenceAlarm",
		"相序错误报警",
		"",
		"相序错误报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"SmokeFireAlarm",
		"烟/火报警",
		"",
		"烟/火报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"LossOfWaterFlowAlarm",
		"缺水报警",
		"",
		"缺水报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"HumidifierHighCurrentAlarm",
		"加湿器过流报警",
		"",
		"加湿器过流告警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"HumidifierPowerLossAlarm",
		"加湿器断电报警",
		"",
		"加湿器断电报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"HumidifierWaterLossAlarm",
		"加湿器缺水报警",
		"",
		"加湿器缺水报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"HumidifierGeneralAlarm",
		"加湿器一般报警",
		"",
		"加湿器一般报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"CWTemperatureHigh",
		"冷冻水高温报警",
		"",
		"冷冻水高温报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"CWValveFailureWaterFlowLow",
		"冷冻水阀故障或水流低报警",
		"",
		"冷冻水阀故障或水流低报警：0-正常，1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"RoomTempSensorFailed",
		"室内温度传感器故障",
		"",
		"室内温度传感器故障：0-正常，1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"RoomHumiSensorFailed",
		"室内湿度传感器故障",
		"",
		"室内湿度传感器故障：0-正常，1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"OutdoorTempSensorFailed",
		"室外温度传感器故障",
		"",
		"室外温度传感器故障：0-正常，1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"DeliveryAirTempSensorFailed",
		"送风温度传感器故障",
		"",
		"送风温度传感器故障：0-正常，1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"RoomTemperature",
		"室内温度",
		"°C",
		"室内温度",
		0,
		0,
		"室内温度过高",
		"室内温度过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutdoorTemperature",
		"室外温度",
		"°C",
		"室外温度",
		0,
		0,
		"室外温度过高",
		"室外温度过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"DeliveryAirTemperature",
		"送风温度",
		"°C",
		"送风温度",
		0,
		0,
		"送风温度过高",
		"送风温度过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"InChilledWaterTemperature",
		"冷水进水温度",
		"°C",
		"冷冻水温度",
		0,
		0,
		"冷冻水温度过高",
		"冷冻水温度过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"OutChilledWaterTemperature",
		"冷水出水温度",
		"°C",
		"冷水出水温度",
		0,
		0,
		"冷水出水温度过高",
		"冷水出水温度过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"HotWaterTemperature",
		"热水温度",
		"°C",
		"热水温度",
		0,
		0,
		"热水温度过高",
		"热水温度过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"RoomRelativeHumidity",
		"室内湿度",
		"%",
		"室内湿度",
		0,
		0,
		"室内湿度过高",
		"室内湿度过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"CoolingSetpoint",
		"制冷设定值",
		"°C",
		"制冷设定值",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"CoolingSensitivity",
		"制冷精度",
		"°C",
		"制冷精度",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"HeatingSetpoint",
		"制热设定值",
		"°C",
		"制热设定值",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"HeatingSensitivity",
		"制热精度",
		"°C",
		"制热精度",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"DehumidificationSetpoint",
		"除湿设定值",
		"%",
		"除湿设定值",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"DehumidificationSensitivity",
		"除湿精度",
		"%",
		"除湿精度",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"HumidificationSetpoint",
		"加湿设定值",
		"%",
		"加湿设定值",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"HumidificationSensitivity",
		"加湿精度",
		"%",
		"加湿精度",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"Circuit1EvaporatingPressure",
		"回路1蒸发器压力",
		"bar",
		"回路1蒸发器压力",
		0,
		0,
		"回路1蒸发器压力过高",
		"回路1蒸发器压力过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"Circuit2EvaporatingPressure",
		"回路2蒸发器压力",
		"bar",
		"回路2蒸发器压力",
		0,
		0,
		"回路2蒸发器压力过高",
		"回路2蒸发器压力过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"Circuit1SuctionTemperature",
		"回路1吸气温度",
		"℃",
		"回路1吸气温度",
		0,
		0,
		"回路1吸气温度过高",
		"回路1吸气温度过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"Circuit2SuctionTemperature",
		"回路2吸气温度",
		"℃",
		"回路2吸气温度",
		0,
		0,
		"回路2吸气温度过高",
		"回路2吸气温度过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"Circuit1EvaporatingTemperature",
		"回路1蒸发器温度",
		"℃",
		"回路1蒸发器温度",
		0,
		0,
		"回路1蒸发器温度过高",
		"回路1蒸发器温度过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"Circuit2EvaporatingTemperature",
		"回路2蒸发器温度",
		"℃",
		"回路2蒸发器温度",
		0,
		0,
		"回路2蒸发器温度过高",
		"回路2蒸发器温度过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"Circuit1Superheat",
		"回路1过热度",
		"℃",
		"回路1过热度",
		0,
		0,
		"回路1过热度过高",
		"回路1过热度过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"Circuit2Superheat",
		"回路2过热度",
		"℃",
		"回路2过热度",
		0,
		0,
		"回路2过热度过高",
		"回路2过热度过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"ColdWaterValveRamp",
		"冷水阀开度",
		"%",
		"冷水阀开度",
		0,
		0,
		"冷水阀开度过高",
		"冷水阀开度过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"HotWaterValveRamp",
		"热水阀开度",
		"%",
		"热水阀开度",
		0,
		0,
		"热水阀开度过高",
		"热水阀开度过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"EvaporatingFanSpeed",
		"蒸发器风扇风速",
		"%",
		"蒸发器风扇风速",
		0,
		0,
		"蒸发器风扇风速过高",
		"蒸发器风扇风速过低",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"OnOffStatus",
		"开关机状态",
		"",
		"开关机状态：0-开机，1-关机",
		0,
		0,
		"关机",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AlarmStatus",
		"报警状态",
		"",
		"报警状态：0-正常，1-存在报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	}
};


/**********************************************************************************************************
* 函数名称： static void cmd_fun(short index, int addr, void *data, char *cmd, short *len)
* 函数说明： 生成获取传感器数据指令
* 输入参数： 指令索引，传感器地址，变量结构体指针,以及指令缓存区指针,指令长度
* 返回参数： 无
**********************************************************************************************************/
static void cmd_fun(short index, int addr, void *data, char *cmd, short *len)
{
	switch(index)
	{
		case 0:
			cmd[0] = addr;
			cmd[1] = 0x01;
			cmd[2] = 0x00;								
			cmd[3] = 0x00;
			cmd[4] = 0x00;	
			cmd[5] = 0x60;	
			*len = CRC16_Padding(cmd, 6);
			break;
		case 1:
			cmd[0] = addr;
			cmd[1] = 0x03;
			cmd[2] = 0x00;								
			cmd[3] = 0x00;
			cmd[4] = 0x00;	
			cmd[5] = 0x1A;	
			*len = CRC16_Padding(cmd, 6);			
			break;
		case 2:
			cmd[0] = addr;
			cmd[1] = 0x03;
			cmd[2] = 0x00;								
			cmd[3] = 0x8C;	
			cmd[4] = 0x00;	
			cmd[5] = 0x08;	
			*len = CRC16_Padding(cmd, 6);			
			break;			
		default:
			break;
	}
}


/**********************************************************************************************************
* 函数名称： static int parse_fun(short index, int addr, void *data, char *buf, short len)
* 函数说明： 解析传感器响应的数据，并写入数据库
* 输入参数： 解析索引,传感器地址，变量结构体指针，以及响应数据缓存取指针，响应数据长度
* 返回参数： 返回解析结果，返回0成功，返回1失败
**********************************************************************************************************/
static int parse_fun(short index, int addr, void *data, char *buf, short len)
{
	union{
		short 			dat16;
      	unsigned char  	dat8[2];
    }DAT16_8;						   //数据类型转换	
	Data_Struct	*d = (Data_Struct*)data;

	if(buf!=NULL && buf[0]==addr && len>0 )
	{	
		if(CRC16_Check(buf,len))
		{
			switch(index)
			{
				case 0:
					d->Fan.value.str 	  							  = buf[3]&0x02?"运行":"停止";
					Set_Var_Status(&d->Fan,								buf[3]&0x02?ON:OFF, NULL);	
					d->Compressor.value.str		  					  = buf[3]&0x3C?"运行":"停止";
					Set_Var_Status(&d->Compressor,						buf[3]&0x3C?ON:OFF, NULL);	
					d->Heater.value.str								  = buf[3]&0xC0?"运行":"停止";
					Set_Var_Status(&d->Heater,							buf[3]&0xC0?ON:OFF, NULL);	
					d->Dehumidification.value.str					  = buf[4]&0x04?"运行":"停止";
					Set_Var_Status(&d->Dehumidification,				buf[4]&0x04?ON:OFF, NULL);	
					d->Humidification.value.str						  = buf[4]&0x08?"运行":"停止";
					Set_Var_Status(&d->Humidification,					buf[4]&0x08?ON:OFF, NULL);	
					
					if(buf[5]&0x02){
						d->RoomTemperatureAlarm.value.str	= "高温报警";
						Set_Var_Status(&d->RoomTemperatureAlarm, Alarm, "高温报警");
					}
					else if(buf[5]&0x04){
						d->RoomTemperatureAlarm.value.str	= "低温报警";
						Set_Var_Status(&d->RoomTemperatureAlarm, Alarm, "低温报警");
					}
					else{
						d->RoomTemperatureAlarm.value.str	= "正常";
						Set_Var_Status(&d->RoomTemperatureAlarm, Normal, "正常");
					}				
					
					if(buf[5]&0x80){
						d->RoomHumidityAlarm.value.str	= "高湿报警";
						Set_Var_Status(&d->RoomHumidityAlarm, Alarm, "高湿报警");
					}
					else if(buf[6]&0x01){
						d->RoomHumidityAlarm.value.str	= "低湿报警";
						Set_Var_Status(&d->RoomHumidityAlarm, Alarm, "低湿报警");
					}
					else{
						d->RoomHumidityAlarm.value.str	= "正常";
						Set_Var_Status(&d->RoomTemperatureAlarm, Normal, "正常");
					}				
					
					d->CloggedFilterAlarm.value.str						= buf[6]&0x04?"报警":"正常";
					Set_Var_Status(&d->CloggedFilterAlarm, 				  buf[6]&0x04?Alarm:Normal, NULL);	
					d->FloodingAlarm.value.str							= buf[6]&0x08?"报警":"正常";
					Set_Var_Status(&d->FloodingAlarm, 					  buf[6]&0x08?Alarm:Normal, NULL);
					d->LossOfAirFlowAlarm.value.str						= buf[6]&0x10?"报警":"正常";
					Set_Var_Status(&d->LossOfAirFlowAlarm, 				  buf[6]&0x10?Alarm:Normal, NULL);
					d->HeaterOverheatingAlarm.value.str					= buf[6]&0x20?"报警":"正常";
					Set_Var_Status(&d->HeaterOverheatingAlarm, 			  buf[6]&0x20?Alarm:Normal, NULL);	
					
					if(buf[6]&0x40){
						d->Circuit1PressureAlarm.value.str	= "高压报警";
						Set_Var_Status(&d->Circuit1PressureAlarm, Alarm, "高压报警");
					}
					else if(buf[7]&0x01){
						d->Circuit1PressureAlarm.value.str	= "低压报警";
						Set_Var_Status(&d->Circuit1PressureAlarm, Alarm, "低压报警");
					}
					else{
						d->Circuit1PressureAlarm.value.str	= "正常";
						Set_Var_Status(&d->Circuit1PressureAlarm, Normal, "正常");
					}				
					
					if(buf[6]&0x80){
						d->Circuit2PressureAlarm.value.str	= "高压报警";
						Set_Var_Status(&d->Circuit2PressureAlarm, Alarm, "高压报警");
					}
					else if(buf[7]&0x02){
						d->Circuit2PressureAlarm.value.str	= "低压报警";
						Set_Var_Status(&d->Circuit2PressureAlarm, Alarm, "低压报警");
					}
					else{
						d->Circuit2PressureAlarm.value.str	= "正常";
						Set_Var_Status(&d->Circuit2PressureAlarm, Normal, "正常");
					}				
									
					d->Circuit1ElectronicValveFailure.value.str			= buf[7]&0x04?"故障":"正常";
					Set_Var_Status(&d->Circuit1ElectronicValveFailure, 	  buf[7]&0x04?Alarm:Normal, NULL);					
					d->Circuit2ElectronicValveFailure.value.str			= buf[7]&0x08?"故障":"正常";
					Set_Var_Status(&d->Circuit2ElectronicValveFailure, 	  buf[7]&0x08?Alarm:Normal, NULL);
					d->WrongPhaseSequenceAlarm.value.str				= buf[7]&0x10?"报警":"正常";
					Set_Var_Status(&d->WrongPhaseSequenceAlarm, 		  buf[7]&0x10?Alarm:Normal, NULL);
					d->SmokeFireAlarm.value.str							= buf[7]&0x20?"报警":"正常";
					Set_Var_Status(&d->SmokeFireAlarm, 					  buf[7]&0x20?Alarm:Normal, NULL);
					d->HumidifierHighCurrentAlarm.value.str				= buf[7]&0x80?"报警":"正常";
					Set_Var_Status(&d->HumidifierHighCurrentAlarm, 		  buf[7]&0x80?Alarm:Normal, NULL);
					
					d->HumidifierPowerLossAlarm.value.str				= buf[8]&0x01?"报警":"正常";
					Set_Var_Status(&d->HumidifierPowerLossAlarm, 		  buf[8]&0x01?Alarm:Normal, NULL);
					d->HumidifierWaterLossAlarm.value.str				= buf[8]&0x02?"报警":"正常";
					Set_Var_Status(&d->HumidifierWaterLossAlarm, 		  buf[8]&0x02?Alarm:Normal, NULL);
					d->CWValveFailureWaterFlowLow.value.str				= buf[8]&0x08?"报警":"正常";
					Set_Var_Status(&d->CWValveFailureWaterFlowLow, 		  buf[8]&0x08?Alarm:Normal, NULL);
					d->LossOfWaterFlowAlarm.value.str					= buf[8]&0x10?"报警":"正常";
					Set_Var_Status(&d->LossOfWaterFlowAlarm, 			  buf[8]&0x10?Alarm:Normal, NULL);
					d->CWTemperatureHigh.value.str						= buf[8]&0x20?"报警":"正常";
					Set_Var_Status(&d->CWTemperatureHigh, 				  buf[8]&0x20?Alarm:Normal, NULL);
					d->RoomTempSensorFailed.value.str					= buf[8]&0x40?"故障":"正常";
					Set_Var_Status(&d->RoomTempSensorFailed, 			  buf[8]&0x40?Alarm:Normal, NULL);
					
					d->OutdoorTempSensorFailed.value.str				= buf[9]&0x02?"故障":"正常";
					Set_Var_Status(&d->OutdoorTempSensorFailed, 		  buf[9]&0x02?Alarm:Normal, NULL);
					d->DeliveryAirTempSensorFailed.value.str			= buf[9]&0x04?"故障":"正常";
					Set_Var_Status(&d->DeliveryAirTempSensorFailed, 	  buf[9]&0x04?Alarm:Normal, NULL);	
					d->RoomHumiSensorFailed.value.str					= buf[9]&0x08?"故障":"正常";
					Set_Var_Status(&d->RoomHumiSensorFailed, 			  buf[9]&0x08?Alarm:Normal, NULL);
					
					d->HumidifierGeneralAlarm.value.str					= buf[11]&0x02?"报警":"正常";
					Set_Var_Status(&d->HumidifierGeneralAlarm, 			  buf[11]&0x02?Alarm:Normal, NULL);
					
					d->OnOffStatus.value.str							= buf[12]&0x08?"开机":"关机";
					Set_Var_Status(&d->OnOffStatus, 					  buf[12]&0x08?Normal:Alarm, NULL);					
					
					if(buf[5]||buf[6]||buf[7]||buf[8]||buf[9]||buf[10]&0x7F){
						d->AlarmStatus.value.str						= "存在报警";
						Set_Var_Status(&d->AlarmStatus, Alarm, NULL);							
					}
					else{
						d->AlarmStatus.value.str						= "正常";
						Set_Var_Status(&d->AlarmStatus, Normal, NULL);							
					}
					
					break;
				case 1:
					DAT16_8.dat8[1] = buf[5];
					DAT16_8.dat8[0] = buf[6];
					d->RoomTemperature.value.fnum = DAT16_8.dat16*0.1;
					
					DAT16_8.dat8[1] = buf[7];
					DAT16_8.dat8[0] = buf[8];
					d->OutdoorTemperature.value.fnum = DAT16_8.dat16*0.1;
					
					DAT16_8.dat8[1] = buf[9];
					DAT16_8.dat8[0] = buf[10];
					d->DeliveryAirTemperature.value.fnum = DAT16_8.dat16*0.1;
					
					DAT16_8.dat8[1] = buf[11];
					DAT16_8.dat8[0] = buf[12];
					d->InChilledWaterTemperature.value.fnum = DAT16_8.dat16*0.1;
					
					DAT16_8.dat8[1] = buf[13];
					DAT16_8.dat8[0] = buf[14];
					d->HotWaterTemperature.value.fnum = DAT16_8.dat16*0.1;
					
					DAT16_8.dat8[1] = buf[15];
					DAT16_8.dat8[0] = buf[16];
					d->RoomRelativeHumidity.value.fnum = DAT16_8.dat16*0.1;	
					
					DAT16_8.dat8[1] = buf[17];
					DAT16_8.dat8[0] = buf[18];
					d->OutChilledWaterTemperature.value.fnum = DAT16_8.dat16*0.1;

					DAT16_8.dat8[1] = buf[19];
					DAT16_8.dat8[0] = buf[20];
					d->Circuit1EvaporatingPressure.value.fnum = DAT16_8.dat16*0.1;

					DAT16_8.dat8[1] = buf[21];
					DAT16_8.dat8[0] = buf[22];
					d->Circuit2EvaporatingPressure.value.fnum = DAT16_8.dat16*0.1;

					DAT16_8.dat8[1] = buf[23];
					DAT16_8.dat8[0] = buf[24];
					d->Circuit1SuctionTemperature.value.fnum = DAT16_8.dat16*0.1;

					DAT16_8.dat8[1] = buf[25];
					DAT16_8.dat8[0] = buf[26];
					d->Circuit2SuctionTemperature.value.fnum = DAT16_8.dat16*0.1;

					DAT16_8.dat8[1] = buf[27];
					DAT16_8.dat8[0] = buf[28];
					d->Circuit1EvaporatingTemperature.value.fnum = DAT16_8.dat16*0.1;

					DAT16_8.dat8[1] = buf[29];
					DAT16_8.dat8[0] = buf[30];
					d->Circuit2EvaporatingTemperature.value.fnum = DAT16_8.dat16*0.1;

					DAT16_8.dat8[1] = buf[31];
					DAT16_8.dat8[0] = buf[32];
					d->Circuit1Superheat.value.fnum = DAT16_8.dat16*0.1;

					DAT16_8.dat8[1] = buf[33];
					DAT16_8.dat8[0] = buf[34];
					d->Circuit2Superheat.value.fnum = DAT16_8.dat16*0.1;

					DAT16_8.dat8[1] = buf[35];
					DAT16_8.dat8[0] = buf[36];
					d->ColdWaterValveRamp.value.fnum = DAT16_8.dat16*0.1;

					DAT16_8.dat8[1] = buf[37];
					DAT16_8.dat8[0] = buf[38];
					d->HotWaterValveRamp.value.fnum = DAT16_8.dat16*0.1;

					DAT16_8.dat8[1] = buf[39];
					DAT16_8.dat8[0] = buf[40];
					d->EvaporatingFanSpeed.value.fnum = DAT16_8.dat16*0.1;

					DAT16_8.dat8[1] = buf[43];
					DAT16_8.dat8[0] = buf[44];
					d->CoolingSetpoint.value.fnum = DAT16_8.dat16*0.1;
					
					DAT16_8.dat8[1] = buf[45];
					DAT16_8.dat8[0] = buf[46];
					d->CoolingSensitivity.value.fnum = DAT16_8.dat16*0.1;
					
					DAT16_8.dat8[1] = buf[49];
					DAT16_8.dat8[0] = buf[50];
					d->HeatingSetpoint.value.fnum = DAT16_8.dat16*0.1;
					
					DAT16_8.dat8[1] = buf[53];
					DAT16_8.dat8[0] = buf[54];
					d->HeatingSensitivity.value.fnum = DAT16_8.dat16*0.1;
					break;
				case 2:
					DAT16_8.dat8[1] = buf[3];
					DAT16_8.dat8[0] = buf[4];
					d->DehumidificationSensitivity.value.fnum = DAT16_8.dat16*1.0;	
					DAT16_8.dat8[1] = buf[5];
					DAT16_8.dat8[0] = buf[6];
					d->HumidificationSensitivity.value.fnum = DAT16_8.dat16*1.0;				
					DAT16_8.dat8[1] = buf[11];
					DAT16_8.dat8[0] = buf[12];
					d->DehumidificationSetpoint.value.fnum = DAT16_8.dat16*1.0;
					DAT16_8.dat8[1] = buf[15];
					DAT16_8.dat8[0] = buf[16];
					d->HumidificationSetpoint.value.fnum = DAT16_8.dat16*1.0;
					break;
				default:
					break;
			}
			return 0;
		}
	}
	return 1;
}


/**********************************************************************************************************
* 函数名称： void jmkt_TUAR0721_Registration(void)
* 函数说明： 精密空调驱动注册
* 输入参数： 无
* 返回参数： 无
**********************************************************************************************************/
void jmkt_TUAR0721_Registration(void)
{
	DeviceDriverRegistration(
		"jmkt",													//设备类型
		"精密空调",												//设备名称（导航栏默认显示名称）
		"施耐德",												//设备品牌	
		"TUAR0721",												//设备型号
		"适用于施耐德Leonardo系列精密空调，控制器型号为UG40。",	//驱动描述
		var_attr,												//变量属性声明
		sizeof(Data_Struct),									//变量结构体空间大小
		cmd_fun,												//发送指令生成函数
		parse_fun,												//数据解析函数
		500														//设备响应超时时间
	);
		
		
#if 0 || VirtualFrameEN
	#define CMD1 "\x01\x01\x00\x00\x00\x60\x3C\x22"
	#define RSP1 "\x01\x01\x0C\x02\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\xE8\xB7"	
	#define CMD2 "\x01\x03\x00\x00\x00\x1A\xC4\x01"
	#define RSP2 "\x01\x03\x34\x00\x00\x00\xEC\x00\x00\x00\x00\x00\x00\x00\x00\x00\xC9\x00\x00\x00\x44\x00\x00\x00\xEC\x00\x00\x00\x91\x00\x00\x00\x5B\x00\x00\x00\x00\x00\x00\x02\x26\x00\x00\x00\xEB\x00\x19\x00\x00\x00\xA7\x00\x00\x00\x0E\xA9\x51"		
	#define CMD3 "\x01\x03\x00\x8C\x00\x08\x85\xE7"
	#define RSP3 "\x01\x03\x0E\x00\x05\x00\x05\x00\x50\x00\x05\x00\x50\x00\x4B\x00\x2D\x00\x23\x5F\x73"			

	VirtualFrameRegistration(CMD1, sizeof(CMD1)-1, RSP1, sizeof(RSP1)-1);		
	VirtualFrameRegistration(CMD2, sizeof(CMD2)-1, RSP2, sizeof(RSP2)-1);		
	VirtualFrameRegistration(CMD3, sizeof(CMD3)-1, RSP3, sizeof(RSP3)-1);	
#endif		
}

